﻿#region 命名空间

using System;
using System.Data;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Model.Attribute;
using WinnerCMS.WebFactory;

#endregion

namespace WinnerCMS.WebUI.Admin.Shop
{
    [Access("GoodsRank")]
    public partial class GoodsRank : PageBase
    {
        private byte ModelId;
        private decimal sumX;
        private decimal sumY;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.ModelId = byte.Parse(Request.QueryString["ModelId"]);
            if (!IsPostBack)
            {
                this.lblPath.Text = string.Format("{0} → 销售 → <a href='GoodsRank.aspx?ModelId={1}'>销售统计/排行</a>",
                    ModelManage.GetModelName(this.ModelId), this.ModelId);
                BindList(0);
            }
        }

        private void BindList(int Type)
        {
            this.GV_List.EmptyDataTemplate = GetTemplate(this);
            new OrderListManage().Rank(this.GV_List, Type);
        }

        protected void ddlTotal_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindList(int.Parse(this.ddlTotal.SelectedValue));
        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var myrows = (DataRowView) e.Row.DataItem;
                this.sumX += decimal.Parse(myrows[2].ToString());
                this.sumY += decimal.Parse(myrows[3].ToString());
            }
            // 合计
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[2].Text = "合计";
                e.Row.Cells[2].HorizontalAlign = HorizontalAlign.Center;

                e.Row.Cells[3].Text = this.sumX.ToString();
                e.Row.Cells[3].HorizontalAlign = HorizontalAlign.Right;

                e.Row.Cells[4].Text = this.sumY.ToString("C");
                e.Row.Cells[4].HorizontalAlign = HorizontalAlign.Right;
            }
        }
    }
}